home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / osrc.arc / TCPDUMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-13  |  1.5 KB  |  70 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "timer.h"
  7. #include "tcp.h"
  8. #include "trace.h"
  9.  
  10. /* TCP segment header flags */
  11. char *Tcpflags[] = {
  12.     "FIN",    /* 0x01 */
  13.     "SYN",    /* 0x02 */
  14.     "RST",    /* 0x04 */
  15.     "PSH",    /* 0x08 */
  16.     "ACK",    /* 0x10 */
  17.     "URG"    /* 0x20 */
  18. };
  19.  
  20. /* Dump a TCP segment header. Assumed to be in network byte order */
  21. void
  22. tcp_dump(bpp,source,dest,check)
  23. struct mbuf **bpp;
  24. int32 source,dest;    /* IP source and dest addresses */
  25. int check;        /* 0 if checksum test is to be bypassed */
  26. {
  27.     struct tcp seg;
  28.     struct pseudo_header ph;
  29.     int16 csum;
  30.  
  31.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  32.         return;
  33.  
  34.     /* Verify checksum */
  35.     ph.source = source;
  36.     ph.dest = dest;
  37.     ph.protocol = TCP_PTCL;
  38.     ph.length = len_mbuf(*bpp);
  39.     csum = cksum(&ph,*bpp,ph.length);
  40.  
  41.     ntohtcp(&seg,bpp);
  42.  
  43.     printf("TCP: %u->%u Seq x%lx",seg.source,seg.dest,seg.seq,seg.ack);
  44.     if(seg.flags.ack)
  45.         printf(" Ack x%lx",seg.ack);
  46.     if(seg.flags.urg)
  47.         printf(" %s",Tcpflags[5]);
  48.     if(seg.flags.ack)
  49.         printf(" %s",Tcpflags[4]);
  50.     if(seg.flags.psh)
  51.         printf(" %s",Tcpflags[3]);
  52.     if(seg.flags.rst)
  53.         printf(" %s",Tcpflags[2]);
  54.     if(seg.flags.syn)
  55.         printf(" %s",Tcpflags[1]);
  56.     if(seg.flags.fin)
  57.         printf(" %s",Tcpflags[0]);
  58.  
  59.     printf(" Wnd %u",seg.wnd);
  60.     if(seg.flags.urg)
  61.         printf(" UP x%x",seg.up);
  62.     /* Print options, if any */
  63.     if(seg.mss != 0)
  64.         printf(" MSS %u",seg.mss);
  65.     if(check && csum != 0)
  66.         printf(" CHECKSUM ERROR (%u)",csum);
  67.     printf("\n");
  68. }
  69.  
  70.